#include <stdio.h>
#include <stdlib.h>
#include "aimage.h"
#include "aimage_utils.h"
#include "aimage_ppm.h"

int main( int argc, char *argv[] )
{
	AIMAGE image;
	float mult, cutoff;

	if ( argc != 3 && argc != 4 )
	{
		fprintf(stderr, "%s multiplier cutoff [in_file]\n", argv[0] );
		exit( 1 );
	}

	mult = atof( argv[1] );
	if ( mult <= 0 )
	{
		fprintf(stderr, "%s multiplier must be greater than 0\n",
			argv[0] );
		exit( 1 );
	}
	cutoff = atof( argv[2] );
	if ( cutoff < 0 || cutoff > 1 )
	{
		fprintf(stderr, "%s cutoff must be between 0 and 1\n",
			argv[0] );
		exit( 1 );
	}
	if ( argc == 4 )
	{
		fprintf(stderr,"stretch reading from %s, mult %g cutoff %g\n", 
			argv[4], mult, cutoff );
		AIMAGE_PPM_UTILS::load( image, argv[4] );
	}
	else
	{
		fprintf(stderr,"stretch reading from stdin, mult %g cutoff %g\n", 
			mult, cutoff );
		AIMAGE_PPM_UTILS::load( image, "stdin" );
	}

	AIU::stretch( image, mult, cutoff );

	AIMAGE_PPM_UTILS::save( image, "stdout", true );
}

